/*
 * Copyright (C) 2010 Rodion Volkov (volkov.rodion@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.rchik.divermate;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DiveLogActivity extends AdvertisingActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.history);
		
		LinearLayout hLayout = (LinearLayout)findViewById(R.id.HorizontalLayout);
		
		ArrayList<DiveLogElement> log = DivingMenu.getDiveLog();
		
		View elementView; 
		
		for ( DiveLogElement diveLogElement : log )
		{
			switch ( diveLogElement.getLogType() )
			{
				case Dive:
				{
					elementView = getLayoutInflater().inflate(R.layout.dive_element, null);
					
					LevelIndicator.IndicateLevel(elementView, diveLogElement.getInitialLevel());
					
					((TextView)elementView.findViewById(R.id.DepthTextView))
						.setText((Integer)diveLogElement.getParams().get("Depth")+"");
					
					((TextView)elementView.findViewById(R.id.TimeTextView))
						.setText((String)diveLogElement.getParams().get("Time"));
					
					int depthMetric = (Integer)diveLogElement.getParams().get("DepthMetric");
					int metricResourceId = DivingMenu.getMetricTypes().get(depthMetric).getLogResourceId();
					
					((ImageView)elementView.findViewById(R.id.DepthImageView))
						.setImageResource(metricResourceId);
					
					hLayout.addView(elementView);
					
					break;
				}
				case Rest:
				{
					elementView = getLayoutInflater().inflate(R.layout.rest_element, null);
					
					LevelIndicator.IndicateLevel(elementView, diveLogElement.getInitialLevel());
					
					((TextView)elementView.findViewById(R.id.TimeTextView))
						.setText((String)diveLogElement.getParams().get("Time"));
					
					hLayout.addView(elementView);
					
					break;
				}
			}
		}

		elementView = getLayoutInflater().inflate(R.layout.final_element, null);
		
		LevelIndicator.IndicateLevel(elementView, DivingMenu.getCurrentNitroLevel());
		
		hLayout.addView(elementView);
		
		LevelIndicator.IndicateLevel(findViewById(R.id.TopLayout), DivingMenu.getCurrentNitroLevel());
	}

}
